package Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/listStudent")
public class listStudent extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader("C:\\Users\\Admin\\Desktop\\1.txt"));
        ArrayList<Stu> stus = new ArrayList<Stu>();
        String len;
        while ((len=bufferedReader.readLine())!=null){
            String[] split = len.split(",");
            Stu stu = new Stu(split[0],split[1],split[2]);
            stus.add(stu);
        }
        req.getSession().setAttribute("Students",stus);
        resp.sendRedirect("/jsp/listStudent.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
